package com.gxa.dao.impl;

import com.gxa.dao.DepartmentDao;
import com.gxa.dbutils.JdbcBuild;
import com.gxa.pojo.Department;

import java.sql.SQLException;
import java.util.List;

public class DepartmentDaoImpl extends JdbcBuild implements DepartmentDao {
    @Override
    public List<Department> queryDepartmentList(Integer param01, Integer param02) throws SQLException {
        String sql = "select * from department limit ?,?";
        Object[] params = {param01,param02};
        List<Department> list = super.queryListEntity(Department.class, sql, params);
        return list;
    }

    @Override
    public Integer countDepartment() throws SQLException {
        String sql = "select count(*) from department";
        int result = super.findAllForInt(sql, null);
        return result;
    }

    @Override
    public int add(Department department,String date) throws SQLException {
        String sql = "insert into department(deparment_num,name,mark,update_time) values(?,?,?,?)";
        Object[] params = {department.getDeparment_num(),department.getName(),department.getMark(),date};
        int result = super.executeUpdate(sql, params);
        return result;
    }

    @Override
    public int delDepartment(String id) throws SQLException {
        String sql = "delete from department where id=?";
        Object[] params = {id};
        int result = super.executeUpdate(sql, params);
        return result;
    }

    @Override
    public int mod(Department department, String date) throws SQLException {
        String sql = "update department set deparment_num=?,name=?,mark=?,update_time=? where id=?";
        Object[] params = {department.getDeparment_num(),department.getName(),department.getMark(),date,department.getId()};
        int result = super.executeUpdate(sql, params);
        return result;
    }

    @Override
    public List<Department> searchDepartment(Integer param01, Integer param02,String name) throws SQLException {
        String sql = "select * from department where name=? limit ?,?";
        Object[] params = {name,param01,param02};
        List<Department> list = super.queryListEntity(Department.class, sql, params);
        return list;
    }

    @Override
    public Integer countDepartment(String name) throws SQLException {
        String sql = "select count(*) from department where name=?";
        Object[] params = {name,};
        int result = super.findAllForInt(sql, params);
        return result;
    }
}
